<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'

// route 来获取路由参数
// route 来获取路由参数--查询参数 ?key=value
// const route = useRoute()

// const key = ref('黑马程序员')

// onMounted(() => {
//   // 查询参数 通过 query 接收
//   console.log(route.query)
//   console.log(route.query.key)
//   key.value = route.query.key
// })

// route 来获取路由参数--动态路由传参 /xxx
const route = useRoute()

const key = ref('黑马程序员')

onMounted(() => {
  // 查询参数 通过 query 接收
  console.log(route.params)
  key.value = route.params.key as string
})
</script>

<template>
  <div class="search">
    <p>搜索关键字: {{ key }}</p>
    <p>搜索结果:</p>
    <ul>
      <li>.............</li>
      <li>.............</li>
      <li>.............</li>
      <li>.............</li>
    </ul>
  </div>
</template>

<style>
.search {
  width: 400px;
  height: 240px;
  padding: 0 20px;
  margin: 0 auto;
  border: 2px solid #c4c7ce;
  border-radius: 5px;
}
</style>
